package org.micro.frame.multiple;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Aspect
@Component
public class MultipleLogAspect {

    @Before("@annotation(multipleAspect)")
    public void before(JoinPoint joinPoint, MultipleAspect multipleAspect) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        log.info("url: {}", request.getRequestURL());
        log.info("method: {}", request.getMethod());
        log.info("ip: {}", request.getRemoteAddr());
        log.info("类名: {}", joinPoint.getSignature().getDeclaringTypeName());
        log.info("方法名: {}", joinPoint.getSignature().getName());
        log.info("请求参数: {}", joinPoint.getArgs());
        log.info("请求参数: {}", joinPoint.getArgs());
        log.info("MultipleAspect: {}", multipleAspect.value());

    }

    @After("@annotation(multipleAspect)")
    public void after(JoinPoint joinPoint, MultipleAspect multipleAspect) {

    }

}
